#include "UdpServer.hpp"
#include "Log.hpp"
#include <iostream>
#include <memory>
#include "Route.hpp"
#include "ThreadPool.hpp"
#include <functional>

using namespace ThreadPoolModule;

using task_t = std::function<void()>;

int main(int args,char* argv[])
{
    if(args != 2)
    {
        std::cout << "you shoule enter: port" << std::endl;
        exit(1);
    }
    Enable_Console_Log_Strategy();
    uint16_t port = std::stoi(argv[1]);
   
    Route r;
    
    //2.创建线程池,其实线程池早就创建了，这里只不过是获取单例，通过单例访问线程池中的属性
    auto tp = ThreadPool<task_t>::GetInstStance();

    std::unique_ptr<UdpServe> usvr = std::make_unique<UdpServe>(port,[&r,&tp](int sockfd,const std::string& message ,InetAddr& client){
        task_t t = std::bind(&Route::MessageRoute,&r,sockfd,message,client);//bind  绑定成员函数时，第二个参数是实例化的对象
        tp->Equeue(t);
    });
    usvr->Init();
    usvr->start();

    return 0;
}